//
//  LMStatusFrame.m
//  李明微博
//
//  Created by apple on 15/12/16.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMStatusFrame.h"
#import "CZStatus.h"
#import "CZUser.h"

#define LMStatusCellMargin 10


@implementation LMStatusFrame

- (void)setStatus:(CZStatus *)status
{
    _status = status;
    
    [self setUpOriginalViewFrame];
    
    CGFloat toolBarY = CGRectGetMaxY(_originalViewFrame);
    
    if (status.retweeted_status) {
        
        [self setUpRetweetViewFrame];
        toolBarY = CGRectGetMaxY(_retweetViewFrame);
    }
    
    CGFloat toolframe =[self setUpToolViewFrameWithToolBarY:toolBarY];
    
    NSLog(@"---------%f",toolframe);
    
    _cellheight = toolframe;
    
}


- (void)setUpOriginalViewFrame
{
    CGFloat imageX = LMStatusCellMargin;
    CGFloat imageY = imageX+10;
    CGFloat imageWH = 35;
    
    _originalIconFrame = CGRectMake(imageX, imageY, imageWH, imageWH);
    
    CGFloat nameX = CGRectGetMaxX(_originalIconFrame)+LMStatusCellMargin;
    CGFloat nameY = imageY;
    
    CGSize nameSize =[_status.user.name sizeWithFont:[UIFont systemFontOfSize:13]];
    _originalNameFrame =(CGRect){{nameX,nameY},nameSize};
    
    if (_status.user.isVip) {
        CGFloat vipX = CGRectGetMaxX(_originalNameFrame)+LMStatusCellMargin;
        CGFloat vipY = imageY;
        CGFloat vipW = 14;
        CGFloat vipH = 14;
        _originalVipFrame = CGRectMake(vipX, vipY, vipW, vipH);
    }
    
    
    CGFloat timeX = CGRectGetMaxX(_originalIconFrame)+LMStatusCellMargin;
    CGFloat timeY = CGRectGetMaxY(_originalNameFrame) + 5;
    
    CGSize timeSize =[_status.created_at sizeWithFont:[UIFont systemFontOfSize:11]];
    _originalTimeFrame =(CGRect){{timeX,timeY},timeSize};
    
    
    CGFloat sourceX =CGRectGetMaxX(_originalTimeFrame)+LMStatusCellMargin;
    CGFloat sourceY = CGRectGetMaxY(_originalNameFrame) + 5;
    CGSize sourceSize =[_status.source sizeWithFont:[UIFont systemFontOfSize:11]];
    _originalSourceFrame =(CGRect){{sourceX,sourceY},sourceSize};
    
    
    CGFloat textX =LMStatusCellMargin;
    CGFloat textY = CGRectGetMaxY(_originalIconFrame) + LMStatusCellMargin;
    CGFloat screenW =[UIScreen mainScreen].bounds.size.width;
    CGFloat textW = screenW - 3*LMStatusCellMargin;
    CGSize textSize =[_status.text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(screenW, CGFLOAT_MAX)];
    _originalTextFrame =(CGRect){{textX,textY},textSize};
    
    
    //原创微博的frame
    
    CGFloat orginX = 0;
    CGFloat orginY = 0;
    CGFloat orginW =[UIScreen mainScreen].bounds.size.width;
    CGFloat orginH = CGRectGetMaxY(_originalTextFrame) +LMStatusCellMargin;
    
    _originalViewFrame = CGRectMake(orginX, orginY, orginW, orginH);


    
    
}



- (void)setUpRetweetViewFrame
{
    CGFloat nameX = LMStatusCellMargin;
    CGFloat nameY = CGRectGetMaxY(_originalViewFrame)+LMStatusCellMargin;
    
    CGSize nameSize =[_status.retweeted_status.user.name sizeWithFont:[UIFont systemFontOfSize:13]];
    _retweetNameFrame =(CGRect){{nameX,nameY},nameSize};
    
    
    CGFloat textX =LMStatusCellMargin;
    CGFloat textY = CGRectGetMaxY(_retweetNameFrame) + LMStatusCellMargin;
    CGFloat screenW =[UIScreen mainScreen].bounds.size.width;
    CGFloat textW = screenW - 3*LMStatusCellMargin;
    CGSize textSize =[_status.text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(screenW, CGFLOAT_MAX)];
    _retweetTextFrame =(CGRect){{textX,textY},textSize};
    
    
    
    
    //原创微博的frame
    
    CGFloat retweetX = 0;
    CGFloat retweetY = CGRectGetMaxY(_originalViewFrame) + LMStatusCellMargin;
    CGFloat retweetW =[UIScreen mainScreen].bounds.size.width;
    CGFloat retweetH = CGRectGetMaxY(_retweetTextFrame) +LMStatusCellMargin;
    _retweetViewFrame = CGRectMake(retweetX, retweetY, retweetW, retweetH);
    
}


- (CGFloat)setUpToolViewFrameWithToolBarY:(CGFloat) toolBarY
{
    CGFloat toolBarX = 0;
    CGFloat toolBarW = [UIScreen mainScreen].bounds.size.width;
    CGFloat toolBarH = 35;
    _toolFrame = CGRectMake(toolBarX, toolBarY, toolBarW, toolBarH);
    return CGRectGetMaxY(_toolFrame);
}

@end
